import os
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment

# 创建工作簿和工作表
wb = Workbook()
ws = wb.active
ws.title = "待办事项"

# 设置列宽
ws.column_dimensions['A'].width = 40
ws.column_dimensions['B'].width = 15
ws.column_dimensions['C'].width = 15
ws.column_dimensions['D'].width = 15

# 设置表头
headers = ['任务描述', '优先级', '截止日期', '完成状态']
for col, header in enumerate(headers, 1):
    cell = ws.cell(row=1, column=col)
    cell.value = header
    cell.font = Font(bold=True)
    cell.fill = PatternFill(start_color='CCCCCC', end_color='CCCCCC', fill_type='solid')
    cell.alignment = Alignment(horizontal='center')

# 添加示例数据
sample_data = [
    ['完成项目文档', '高', '2024-03-15', '进行中'],
    ['代码审查', '中', '2024-03-20', '未开始'],
    ['测试用例编写', '高', '2024-03-18', '未开始']
]

for row, data in enumerate(sample_data, 2):
    for col, value in enumerate(data, 1):
        cell = ws.cell(row=row, column=col)
        cell.value = value
        cell.alignment = Alignment(horizontal='center')

# 确保目录存在
os.makedirs(os.path.dirname(os.path.abspath(__file__)), exist_ok=True)

# 保存文件
wb.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'todo_list.xlsx'))